#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, c;
    cin >> n >> c;
    unordered_map<int, int> mp;
    long long ans = 0;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mp[x]++;
        ans += mp[x + c];
    }
    cout << ans << endl;
}

int main() {
    int t = 1;
    while(t--) solve();
    return 0;
}